﻿using AutoMapper;
using FoodModel;
using J.FoodManageSet.Application.Command.DishesCommand;
using J.FoodRepository.InterFace;
using MediatR;

namespace J.FoodManageSet.Application.CommandHandler.DishesCommandHandler
{
    /// <summary>
    /// 堂食添加
    /// </summary>
    public class DineAddCommandHandler : IRequestHandler<DineAddCommand, int>
    {
        private readonly IDineRepository _dineRepository;
        private readonly IMapper _mapper;

        public DineAddCommandHandler(IDineRepository dineRepository, IMapper mapper)
        {
            _dineRepository = dineRepository;
            _mapper = mapper;
        }
        public async Task<int> Handle(DineAddCommand request, CancellationToken cancellationToken)
        {
            DineModel model = _mapper.Map<DineModel>(request);
            var list = await _dineRepository.DineAdd(model);
            return list;
        }
    }
}
